'use strict';

module.exports = {
    up: async (queryInterface, Sequelize) => {
        const { STRING, INTEGER, DATE, BOOLEAN, NOW } = Sequelize;

        await queryInterface.createTable(
            'tbl_role',
            {
                id: {
                    type: INTEGER,
                    primaryKey: true,
                    autoIncrement: true
                },
                title: {
                    type: STRING(32),
                    allowNull: false
                },
                type: {
                    type: INTEGER,
                    allowNull: false,
                    defaultValue: 0
                },
                status: {
                    type: BOOLEAN,
                    allowNull: false,
                    defaultValue: true
                },
                desc: {
                    type: STRING(64),
                    allowNull: true
                },
                created_at: {
                    type: DATE,
                    allowNull: false,
                    defaultValue: NOW
                },
                updated_at: {
                    type: DATE,
                    allowNull: false,
                    defaultValue: NOW
                }
            },
            {
                charset: 'utf8'
            });

        await queryInterface.createTable(
            'tbl_api_authority',
            {
                id: {
                    type: INTEGER,
                    primaryKey: true,
                    autoIncrement: true
                },
                title: {
                    type: STRING(32),
                    allowNull: false
                },
                type: {
                    type: INTEGER,
                    allowNull: false,
                    defaultValue: 1
                },
                status: {
                    type: BOOLEAN,
                    allowNull: false,
                    defaultValue: true
                },
                path: {
                    type: STRING(32),
                    allowNull: true
                },
                func: {
                    type: STRING(32),
                    allowNull: true
                },
                desc: {
                    type: STRING(64),
                    allowNull: true
                },
                created_at: {
                    type: DATE,
                    allowNull: false,
                    defaultValue: NOW
                },
                updated_at: {
                    type: DATE,
                    allowNull: false,
                    defaultValue: NOW
                }
            },
            {
                charset: 'utf8'
            });

        await queryInterface.createTable(
            'tbl_router_authority',
            {
                id: {
                    type: INTEGER,
                    primaryKey: true,
                    autoIncrement: true
                },
                title: {
                    type: STRING(32),
                    allowNull: false
                },
                type: {
                    type: INTEGER,
                    allowNull: false,
                    defaultValue: 1
                },
                status: {
                    type: BOOLEAN,
                    allowNull: false,
                    defaultValue: true
                },
                parent_id: {
                    type: INTEGER,
                    allowNull: true
                },
                path: {
                    type: STRING(32),
                    allowNull: true
                },
                name: {
                    type: STRING(32),
                    allowNull: true
                },
                component: {
                    type: STRING(32),
                    allowNull: true
                },
                redirect: {
                    type: STRING(64),
                    allowNull: true
                },
                hidden: {
                    type: BOOLEAN,
                    allowNull: true
                },
                icon: {
                    type: STRING(64),
                    allowNull: true
                },
                desc: {
                    type: STRING(64),
                    allowNull: true
                },
                created_at: {
                    type: DATE,
                    allowNull: false,
                    defaultValue: NOW
                },
                updated_at: {
                    type: DATE,
                    allowNull: false,
                    defaultValue: NOW
                }
            },
            {
                charset: 'utf8'
            });

        await queryInterface.createTable(
            'tbl_role_authority',
            {
                id: {
                    type: INTEGER,
                    primaryKey: true,
                    autoIncrement: true
                },
                auth_id: {
                    type: INTEGER,
                    allowNull: false
                },
                role_id: {
                    type: INTEGER,
                    allowNull: false
                },
                type: {
                    type: INTEGER,
                    allowNull: false,
                    defaultValue: 0
                },
                status: {
                    type: BOOLEAN,
                    allowNull: false,
                    defaultValue: true
                },
                desc: {
                    type: STRING(64),
                    allowNull: true
                },
                created_at: {
                    type: DATE,
                    allowNull: false,
                    defaultValue: NOW
                },
                updated_at: {
                    type: DATE,
                    allowNull: false,
                    defaultValue: NOW
                }
            },
            {
                charset: 'utf8'
            });
    },

    down: async (queryInterface, Sequelize) => {
        // await queryInterface.dropTable('tbl_role');
        // await queryInterface.dropTable('tbl_api_authority');
        // await queryInterface.dropTable('tbl_router_authority');
        // await queryInterface.dropTable('tbl_role_authority');
    }
};
